//
//  ErrorView.swift
//  codelabs
//
//  Created by 雷雷 on 26/05/2025.
//

import SwiftUI

struct ErrorView: View {
    let errorWrapper:ErrorWrapper
    
    @Environment(\.dismiss) private var dismiss
    
    var body: some View {
        NavigationStack{
            VStack(alignment:.leading){
                HStack(alignment:.center){
                    Image(systemName:"exclamationmark.triangle.fill")
                        .resizable()
                        .frame(width:32,height:30)
                        .foregroundColor(.red)
                    
                    Text("Error occurred !")
                        .font(.title)
                        .bold()
                        .padding(.leading, 8)
                }
                
                
                Text(errorWrapper.error.localizedDescription)
                    .font(.headline)
                
                Text(errorWrapper.guidance)
                    .font(.caption)
                    .foregroundStyle(.secondary)
                    .padding(.vertical,2)
                
                Spacer()
                
            }
            .frame(maxWidth: .infinity,maxHeight: .infinity)
            .padding()
            .background(.ultraThinMaterial)
            .cornerRadius(16.0)
            .toolbar{
                ToolbarItem(placement: .confirmationAction){
                    Button(action:{dismiss()}){
                        Text("Got it")
                    }
                }
            }
        }
    }
}

#Preview {
    ErrorView(
        errorWrapper: ErrorWrapper(error:SampleError.errorRequired,guidance: "You can safely ignore this error.")    )
}
